package com.ruoyi.petSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.petSys.entity.vo.ApplyAdoptionVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.petSys.domain.ApplyAdoption;
import com.ruoyi.petSys.service.IApplyAdoptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 申请领养Controller
 * 
 * @author ruoyi
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/petSys/applyAdoption")
public class ApplyAdoptionController extends BaseController
{
    @Autowired
    private IApplyAdoptionService applyAdoptionService;

    /**
     * 查询申请领养列表
     */
    @PreAuthorize("@ss.hasPermi('petSys:applyAdoption:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplyAdoption applyAdoption)
    {
        startPage();
        List<ApplyAdoptionVo> list = applyAdoptionService.selectApplyAdoptionList(applyAdoption);
        return getDataTable(list);
    }

    /**
     * 导出申请领养列表
     */
    @PreAuthorize("@ss.hasPermi('petSys:applyAdoption:export')")
    @Log(title = "申请领养", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplyAdoption applyAdoption)
    {
        List<ApplyAdoptionVo> list = applyAdoptionService.selectApplyAdoptionList(applyAdoption);
        ExcelUtil<ApplyAdoptionVo> util = new ExcelUtil<ApplyAdoptionVo>(ApplyAdoptionVo.class);
        util.exportExcel(response, list, "申请领养数据");
    }

    /**
     * 获取申请领养详细信息
     */
    @PreAuthorize("@ss.hasPermi('petSys:applyAdoption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(applyAdoptionService.selectApplyAdoptionById(id));
    }

    /**
     * 新增申请领养
     */
    @PreAuthorize("@ss.hasPermi('petSys:applyAdoption:add')")
    @Log(title = "申请领养", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyAdoption applyAdoption)
    {
        return toAjax(applyAdoptionService.insertApplyAdoption(applyAdoption));
    }

    /**
     * 修改申请领养
     */
    @PreAuthorize("@ss.hasPermi('petSys:applyAdoption:edit')")
    @Log(title = "申请领养", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyAdoption applyAdoption)
    {
        return toAjax(applyAdoptionService.updateApplyAdoption(applyAdoption));
    }

    /**
     * 删除申请领养
     */
    @PreAuthorize("@ss.hasPermi('petSys:applyAdoption:remove')")
    @Log(title = "申请领养", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applyAdoptionService.deleteApplyAdoptionByIds(ids));
    }
}
